﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PoC.Shopkeeper.Data;
using PoC.Shopkeeper.Domain.Models;
using PoC.Shopkeeper.EntityModel;

namespace PoC.Shopkeeper.Domain.Handlers
{
    public class GetAllNews
    {
        private readonly INewsRepository _vehicleRepository;

        public GetAllNews(INewsRepository vehicleRepository)
        {
            _vehicleRepository = vehicleRepository;
        }

        public virtual IList<NewsModel> Execute()
        {
            IList<News> newsData = null;

            try
            {
                newsData = _vehicleRepository.GetAllNews();
            }
            catch (InvalidOperationException e)
            {
                throw e;
                //throw new BusinessServicesException("Unable to retrieve vehicle from database.", e);
            }

            var vehicles = from news in newsData
                           select new NewsModel(news);

            return vehicles.ToList();
        }
    }
}
